package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.service.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName:
 * @Description:
 * @version: v1.1.0
 * @author: shuaiqin
 * @date: 2021/8/31-23:33
 * <p>
 * Modification History:
 * Date         Author          Version            Description
 * ------------------------------------------------------------
 * 2021/8/31          shuaiqin          v1.1.0               修改原因
 */
@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_GlobalTimeHandler")
public class PaymentHystrixController {
    @Resource
    private PaymentHystrixService paymentHystrixService;
    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentOk(@PathVariable("id") Integer id){
        String result = paymentHystrixService.paymentOk(id);
        return result;
    }
//    @HystrixCommand(fallbackMethod = "payment_TimeHandler",commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "5000")
//    })
    @GetMapping("/consumer/payment/hystrix/nok/{id}")
    public String paymentNOk(@PathVariable("id") Integer id){
//        int a=10/0;
        String result = paymentHystrixService.paymentNOk(id);
        return result;
    }
    public String payment_TimeHandler(@PathVariable("id") Integer id){
        return "线程池： "+Thread.currentThread().getName()+"  payment_TimeHandler"+id+"\t"+"客户端降级 稍后再试";
    }
    public String payment_GlobalTimeHandler(){
        return "线程池： "+Thread.currentThread().getName()+"  payment_GlobalTimeHandler"+"\t"+"稍后再试";
    }
}
